}
_addItem(item, page, position) {
- // Append icons to the first page with empty slot, starting from
- // the second page
- if (this._grid.nPages > 1 && page === -1 && position === -1)
- page = this._findBestPageToAppend();
-
this._items.set(item.id, item);
this._grid.addItem(item, page, position);
// Add new app icons, or move existing ones
newApps.forEach(icon => {
const [page, position] = this._getItemPosition(icon);
- if (addedApps.includes(icon))
- this._addItem(icon, page, position);
- else if (page !== -1 && position !== -1)
+ if (addedApps.includes(icon)) {
+ // If there's two pages, newly installed apps should not appear
+ // on page 0
+ if (page === -1 && position === -1 && this._grid.nPages > 1)
+ this._addItem(icon, 1, -1);
+ else
+ this._addItem(icon, page, position);
+ } else if (page !== -1 && position !== -1) {
this._moveItem(icon, page, position);
+ } else {
+ // App is part of a folder
+ }
});
this.emit('view-loaded');
let [page, position] = this._grid.getItemPosition(item);
if (page === -1)
- page = this._findBestPageToAppend(this._grid.currentPage);
+ page = this._grid.currentPage;
return [page, position];
}
this._shouldEaseItems = false;
}
+ _findBestPageToAppend(startPage) {
+ const itemsPerPage = this.columnsPerPage * this.rowsPerPage;
+
+ for (let i = startPage; i < this._pages.length; i++) {
+ const visibleItems = this._pages[i].visibleChildren;
+
+ if (visibleItems.length < itemsPerPage)
+ return i;
+ }
+
+ return this._pages.length;
+ }
+
/**
* addItem:
* @param {Clutter.Actor} item: item to append to the grid
if (!this._container)
return;
+ if (page !== -1 && index === -1)
+ page = this._findBestPageToAppend(page);
+
this._shouldEaseItems = true;
this._container.add_child(item);
this._shouldEaseItems = true;
this._removeItemData(item);
+
+ if (newPage !== -1 && newPosition === -1)
+ newPage = this._findBestPageToAppend(newPage);
+
this._addItemToPage(item, newPage, newPosition);
}